package com.atguigu.cloud.sevice.Impl;/**
 * @Auter zzh
 * @Date 2024/11/13
 */

import com.atguigu.cloud.entities.Shopcar;
import com.atguigu.cloud.sevice.ShopcarService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import com.atguigu.cloud.mapper.ShopcarMapper;

import java.util.List;


/**
 * @projectName: keshe
 * @package: com.atguigu.cloud.sevice.Impl
 * @className: shopcarServiceImpl
 * @author: Eric
 * @description: TODO
 * @date: 2024/11/13 18:01
 * @version: 1.0
 */
@Service
public class ShopcarServiceImpl implements ShopcarService {
    @Resource
    ShopcarMapper shopcarMapper;
    @Override
    public Shopcar getById(Integer id) {

        QueryWrapper<Shopcar> queryWrapper= new QueryWrapper<>();
        queryWrapper.eq("id",id);
        Shopcar shopcar = shopcarMapper.selectOne(queryWrapper);
        return shopcar;
    }

    @Override
    public List<Shopcar> getAll() {
        QueryWrapper<Shopcar> queryWrapper= new QueryWrapper<>();
        List<Shopcar> list_shopcar = shopcarMapper.selectList(queryWrapper);
        return list_shopcar;
    }

    @Override
    public int add(Shopcar shopcar) {
        shopcarMapper.insert(shopcar);
        return shopcar.getId();
    }

    @Override
    public int delete(Integer id) {
        QueryWrapper<Shopcar> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",id);
        int result_id =shopcarMapper.delete(queryWrapper);
        return result_id;
    }

    @Override
    public int update(Shopcar shopcar) {
        int id = shopcar.getId();
        UpdateWrapper<Shopcar> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",id);
        shopcarMapper.update(shopcar,updateWrapper);
        return id;
    }



    @Override
    public Page<Shopcar> Pageuserfind(Integer currentPage, Integer pageSize, Integer userid) {
        Page<Shopcar> page = new Page<>(currentPage, pageSize);
        QueryWrapper<Shopcar> queryWrapper= new QueryWrapper<>();
        queryWrapper.eq("userid",userid);
        shopcarMapper.selectPage(page, queryWrapper);
        return page;
    }


}
